#include<iostream>
#include<string>
#include<queue>
#include<map>
#include<cstring>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10, M = N;
int w[N];
int h[N], e[M], ne[M], w1[M], idx;
LL ans[N];
int d[N];
int cnt;
int n, m, k;
void add(int a, int b, int c)
{
	e[idx] = b,w1[idx] = c, ne[idx] = h[a], h[a] = idx++;
}
void tuopu()
{
	queue<int>q;
	for (int i = 1; i <= n; i++) {
		if (!d[i]) {
			q.push(i);
			ans[i] = w[i];
		}
	}
	while (q.size()) {
		int t = q.front();
		q.pop();
		for (int i = h[t]; ~i; i = ne[i]) {
			int j = e[i];
			ans[j] = max(ans[j], 1ll * w[j]);
			ans[j] = max(ans[t] + w1[i], ans[j]);
			if (--d[j] == 0) {
				q.push(j);
			}
		}
	}
}
int main()
{
	cin >> n >> k >> m;
	for (int i = 1; i <= n; i++) {
		cin >> w[i];
	}
	memset(h, -1, sizeof(h));
	for (int i = 0; i < m; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		add(a, b, c);
		//add(b, a);
		d[b]++;
	}
	tuopu();
	for (int i = 1; i <= n; i++) {
		cout << ans[i] << endl;
	}
	return 0;
}